//@ts-ignore
import Image from './403_error.png'
//@ts-ignore
import style from './index.module.less'
import { useNavigate } from 'react-router-dom'
import { Button } from 'antd'
import { useAppSelector } from '@/store/hooks'
import { Token_Key } from '@/config'
export default function Index() {
  const navigate = useNavigate()
  const menuList = useAppSelector((state) => state.login.menuList)
  const userMenu = useAppSelector((state) => state.login.userRouteList)
  const handleGoBack = () => {
    if (menuList && menuList.length === 0) {
      window.localStorage.setItem(Token_Key, '')
      navigate('/login')
    } else {
      if (window.history.length === 1) {
        const item = userMenu[0]
        if (item.children && item.children.length > 0) {
          navigate(item.children[0].fullPath)
        } else {
          navigate(item.fullPath)
        }
      } else {
        navigate(-1)
      }
    }
  }
  return (
    <div className={style['error-page']}>
      <div className={style.errorWarp}>
        <div className={style.image}>
          <img src={Image}></img>
        </div>
        <div className={style.textWarp}>
          <h4 className={style.desc}>您没有权限访问该页面</h4>
          <h4 className={style.desc}>请联系管理员进行处理</h4>
          <Button className={style.backBtn} size="large" type="dashed" ghost onClick={handleGoBack}>
            返回上一页
          </Button>
        </div>
      </div>
    </div>
  )
}
